$(document).ready(function () {
    var mySwiper = new Swiper('.swiper-container', {
        autoplay: 2000, //可选选项，自动滑动
        loop: true,
        pagination: '.swiper-pagination',
        autoplayDisableOnInteraction: false,

        /*effect: 'fade',
        fade: {
            crossFade: false,
        }*/


        /*effect: 'cube',
        cube: {
            slideShadows: true,
            shadow: false,
            shadowOffset: 100,
            shadowScale: 0.6
        }*/

        /*effect: 'coverflow',
        slidesPerView: 1,
        centeredSlides: true,
        coverflow: {
            rotate: 30,
            stretch: 10,
            depth: 60,
            modifier: 2,
            slideShadows: false
        }*/

    });
});


/* barcode */
$(function () {
    var readercode = $('#code').text();

    $("#bcTarget39").barcode(readercode, "code39", {
        barWidth: 3,
        barHeight: 140
    });
    $("#bcTarget128").barcode(readercode, "code128");
});


/*myscore*/
$(function () {
    var personalG = $('.sgrade tr td:nth-of-type(2)'); //个人成绩
    var classG = $('.sgrade tr td:nth-of-type(3)'); //班平均分
    var gradeG = $('.sgrade tr td:nth-of-type(4)'); //年级平均分


    /*获取的值转换为数组*/
    personalG.each(function (index) {
        personalG[index] = $(this).text();
    });
    classG.each(function (index) {
        classG[index] = $(this).text();
    });
    gradeG.each(function (index) {
        gradeG[index] = $(this).text();
    });


    /*初始化统计图设置*/
    var myChart = echarts.init(document.getElementById('graph'));
    var option = {
        title: {
            show: false, //不显示标题
            noDataLoadingOption: {
                text: '暂无数据',
                effect: 'bubble',
                effectOption: {
                    effect: {
                        n: 0
                    }
                }
            },
        },
        tooltip: {
            textStyle: {
                fontSize: 30 //tip字体大小
            },
            trigger: 'axis',
            axisPointer: {
                type: 'shadow' //tip聚焦模式
            }
        },
        legend: {
            data: ['个人', '班平均', '年级平均'],
            itemGap: 40,
            itemWidth: 30,
            itemHeigth: 25,
            textStyle: {
                fontSize: 36,
            },
        },

        /*y坐标轴设置*/
        yAxis: {
            axisLabel: {
                textStyle: {
                    fontSize: 30 //y坐标字体大小
                }
            },
            data: ['语文', '数学', '英语', '体育', '美术', '音乐'],
            inverse: true
        },
        xAxis: {
            max: 100,
            axisLabel: {
                textStyle: {
                    fontSize: 26 //x坐标字体大小
                }
            }
        },
        /*条形设置*/
        series: [{
            name: '个人',
            type: 'bar',
            data: personalG, //传入个人成绩数据
            }, {
            name: '班平均',
            type: 'bar',
            data: classG, //传入班平均数据
            }, {
            name: '年级平均',
            type: 'bar',
            data: gradeG, //传入年级平均数据
            }],
        animation: false,
        label: {
            normal: {
                show: true,
                textStyle: {
                    fontSize: 24 //柱状图字体大小
                },
                position: 'right'
            }
        },
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
});

/* renew */
$(function () {
    var renews = $('#renew .renewop button'); //获取续借按钮集合
    renews.click(function () {
        var bookname = $(this).parents('.oneoflist').find('.bookname').text(); //获取题名
        var renewtimes = $(this).parents('.oneoflist').find('.renewtimes span:eq(1)'); //获取续借次数dom
        var i = confirm("是否要对《" + bookname + "》进行续借操作");

        if (i && renewtimes.text() > 0) {
            renewtimes.text(renewtimes.text() - 1);
        } else {
            if (i && renewtimes.text() == 0) { //续借次数为0且确认续借
                alert('续借次数为0');
            }
            if (!i) { //取消续借
                return false;
            }
        }
    })
});



/* readingtest */
$(function () {
    var mySwiper2 = new Swiper('.swiper-container2', {
        autoplay: 2000, //可选选项，自动滑动
        loop: true,
        autoplayDisableOnInteraction: false,

        effect: 'fade',
        fade: {
            crossFade: false,
        }
    });


    var inputs = $('#choise input');

    inputs.click(function () {
        var inputporn = $('#choise input[name="porn"]:checked').val(); //通过未通过checked状态的value
        var catechecked = $(this).is(':checked');
        //alert(catechecked);
        var inputcate = $('#choise input[name="category"]:checked').val(); //类目checked状态的value
        var booknopass = $('#readingtest .book-nopass');
        var bookpass = $('#readingtest .book-pass');
        if ($(this).attr('checked')) {
            //alert($(this).attr('checked'));
            $(this).removeAttr('checked');
        } else {
            $(this).attr('checked', 'checked');
        }
        if (inputporn == 1) {
            bookpass.css('display', 'none');
            booknopass.css('display', 'block');

        } else {
            booknopass.css('display', 'none');
            bookpass.css('display', 'block');
        }
    });
});

/* readingtest-pass  */
$(function () {
    $('#readingtest-pass .return,#readingtest-nopass .return').click(function () {
        history.back(-1);
    });
    
    $('#readingtest-pass .share').click(function(){
       $('#readingtest-pass .displaynone').fadeToggle(); 
    });
    $('#readingtest-pass .close').click(function(){
       $('#readingtest-pass .displaynone').fadeOut(); 
    });
    
    $('#readingtest-nopass .startanswer').click(function(){
       window.location.href='readingtest-question.html' 
    });

});
